home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / sys / buf.h < prev    next >
Text File  |  1995-02-14  |  8KB  |  235 lines

  1. /*
  2.  * Copyright (c) 1982, 1986 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  *
  6.  *    @(#)buf.h    7.1 (Berkeley) 6/4/86
  7.  *
  8.  * History
  9.  * 05-Jul-90    Doug Mitchell at NeXT
  10.  *    Added B_KERNSPACE flag.
  11.  */
  12.  
  13. #ifndef    _SYS_BUF_
  14. #define    _SYS_BUF_
  15.  
  16. #import <sys/types.h>
  17.  
  18. /*
  19.  * The header for buffers in the buffer pool and otherwise used
  20.  * to describe a block i/o request is given here.  The routines
  21.  * which manipulate these things are given in bio.c.
  22.  *
  23.  * Each buffer in the pool is usually doubly linked into 2 lists:
  24.  * hashed into a chain by <dev,blkno> so it can be located in the cache,
  25.  * and (usually) on (one of several) queues.  These lists are circular and
  26.  * doubly linked for easy removal.
  27.  *
  28.  * There are currently three queues for buffers:
  29.  *    one for buffers which must be kept permanently (super blocks)
  30.  *     one for buffers containing ``useful'' information (the cache)
  31.  *    one for buffers containing ``non-useful'' information
  32.  *        (and empty buffers, pushed onto the front)
  33.  * The latter two queues contain the buffers which are available for
  34.  * reallocation, are kept in lru order.  When not on one of these queues,
  35.  * the buffers are ``checked out'' to drivers which use the available list
  36.  * pointers to keep track of them in their i/o active queues.
  37.  */
  38.  
  39. /*
  40.  * Bufhd structures used at the head of the hashed buffer queues.
  41.  * We only need three words for these, so this abbreviated
  42.  * definition saves some space.
  43.  */
  44. struct bufhd
  45. {
  46.     long    b_flags;        /* see defines below */
  47.     struct    buf *b_forw, *b_back;    /* fwd/bkwd pointer in chain */
  48. };
  49. struct buf
  50. {
  51.     long    b_flags;        /* too much goes here to describe */
  52.     struct    buf *b_forw, *b_back;    /* hash chain (2 way street) */
  53.     struct    buf *av_forw, *av_back;    /* position on free list if not BUSY */
  54. #define    b_actf    av_forw            /* alternate names for driver queue */
  55. #define    b_actl    av_back            /*    head - isn't history wonderful */
  56.     long    b_bcount;        /* transfer count */
  57.     long    b_bufsize;        /* size of allocated buffer */
  58. #define    b_active b_bcount        /* driver queue head: drive active */
  59.     short    b_error;        /* returned after I/O */
  60.     dev_t    b_dev;            /* major+minor device name */
  61.     union {
  62.         caddr_t b_addr;        /* low order core address */
  63.         int    *b_words;        /* words for clearing */
  64.         struct fs *b_fs;        /* superblocks */
  65.         struct csum *b_cs;        /* superblock summary information */
  66.         struct cg *b_cg;        /* cylinder group block */
  67.         struct dinode *b_dino;    /* ilist */
  68.         daddr_t *b_daddr;        /* indirect block */
  69.     } b_un;
  70.     daddr_t    b_blkno;        /* block # on device */
  71.     long    b_resid;        /* words not transferred after error */
  72. #define    b_errcnt b_resid        /* while i/o in progress: # retries */
  73.     struct  proc *b_proc;        /* proc doing physical or swap I/O */
  74.     int    (*b_iodone)();        /* function called by iodone */
  75.     int    b_pfcent;        /* center page when swapping cluster */
  76. #ifdef    NeXT
  77.     int    b_sort_key;        /* used by disk sort */
  78.     int    b_rtpri;        /* realtime priority */
  79. #define    RTPRI_NONE    0
  80. #define    RTPRI_MIN    1
  81. #define    RTPRI_MAX    127
  82. #ifdef hppa
  83.     unsigned long    b_spaddr;    /* space id of b_un.b_addr */
  84.     int        b_dev_mapped;    /* remapped b_dev. */
  85.     daddr_t        b_offset;       /* byte offset on device. */
  86.     long        b_scratch1;     /* scratch for I/O drivers. */
  87. #endif hppa
  88.  
  89. #endif    NeXT
  90.     struct  vnode *b_vp;            /* vnode associated with block */
  91. };
  92.  
  93. #define    BQUEUES        4        /* number of free buffer queues */
  94.  
  95. #define    BQ_LOCKED    0        /* super-blocks &c */
  96. #define    BQ_LRU        1        /* lru, useful buffers */
  97. #define    BQ_AGE        2        /* rubbish */
  98. #define    BQ_EMPTY    3        /* buffer headers with no memory */
  99.  
  100. #ifdef    KERNEL
  101. #if    NeXT
  102. #define    BUFHSZ    16
  103. #else    NeXT
  104. #define    BUFHSZ    512
  105. #endif    NeXT
  106. #define RND    (MAXBSIZE/1024)
  107. #define    BUFHASH(dvp, dblkno)    \
  108.     ((struct buf *)&bufhash[((u_int)(dvp)+(((int)(dblkno))/RND)) % BUFHSZ])
  109.  
  110. struct    buf *buf;        /* the buffer pool itself */
  111. char    *buffers;
  112. int    nbuf;            /* number of buffer headers */
  113. int    bufpages;        /* number of memory pages in the buffer pool */
  114. struct    bufhd bufhash[BUFHSZ];    /* heads of hash lists */
  115. struct    buf bfreelist[BQUEUES];    /* heads of available lists */
  116. #if NeXT
  117. struct    buf *swbuf;        
  118. struct    buf *swbuf_freelist;        
  119. struct    buf *swbuf_cleanlist;        
  120. int     nswbuf;        
  121. #endif
  122.  
  123. struct    buf *alloc();
  124. struct    buf *realloccg();
  125. struct    buf *baddr();
  126. struct    buf *getblk();
  127. struct    buf *geteblk();
  128. struct    buf *getnewbuf();
  129. struct    buf *bread();
  130. struct    buf *breada();
  131. #if    NeXT
  132. struct    buf *getemptybuf();
  133. struct    buf *getpblk();
  134. struct    buf *breadp();
  135. #endif    NeXT
  136. struct    vnode *bdevvp();    /* Added for use by the specfs routines */
  137.  
  138. unsigned minphys();
  139. #endif
  140.  
  141. /*
  142.  * These flags are kept in b_flags.
  143.  */
  144. #define    B_WRITE        0x00000000    /* non-read pseudo-flag */
  145. #define    B_READ        0x00000001    /* read when I/O occurs */
  146. #define    B_DONE        0x00000002    /* transaction finished */
  147. #define    B_ERROR        0x00000004    /* transaction aborted */
  148. #define    B_BUSY        0x00000008    /* not on av_forw/back list */
  149. #define    B_PHYS        0x00000010    /* physical IO */
  150. #define    B_XXX        0x00000020    /* was B_MAP, alloc UNIBUS on pdp-11 */
  151. #define    B_WANTED    0x00000040    /* issue wakeup when BUSY goes off */
  152. #define    B_AGE        0x00000080    /* delayed write for correct aging */
  153. #define    B_ASYNC        0x00000100    /* don't wait for I/O completion */
  154. #define    B_DELWRI    0x00000200    /* write at exit of avail list */
  155. #define    B_TAPE        0x00000400    /* this is a magtape (no bdwrite) */
  156. #if NeXT
  157. #define    B_PAGEOUT    0x00000800    /* Pageout operation */
  158. #define    B_PAGEIN    0x00001000    /* Pagein operation */
  159. #else
  160. #define    B_UAREA        0x00000800    /* add u-area to a swap operation */
  161. #define    B_PAGET        0x00001000    /* page in/out of page table space */
  162. #define    B_PGIN        0x00004000    /* pagein op, so swap() can count it */
  163. #endif
  164. #define    B_DIRTY        0x00002000    /* dirty page to be pushed out async */
  165. #define    B_CACHE        0x00008000    /* did bread find us in the cache ? */
  166. #define    B_INVAL        0x00010000    /* does not contain valid info  */
  167. #define    B_LOCKED    0x00020000    /* locked in core (not reusable) */
  168. #define    B_HEAD        0x00040000    /* a buffer header, not a buffer */
  169. #define    B_BAD        0x00100000    /* bad block revectoring in progress */
  170. #define    B_CALL        0x00200000    /* call b_iodone from iodone */
  171. #define    B_NOCACHE    0x00400000    /* don't cache block when released */
  172. #define B_PRIVATE    0x02000000    /* memory attached to buffer is private */
  173. #define B_KERNSPACE    0x04000000    /* physical I/O to kernel space */
  174.  
  175. #define    B_SCRACH5    0x40000000    /* Used by device drivers. */
  176. #define    B_SCRACH6    0x80000000    /* Used by device drivers. */
  177.  
  178. /*
  179.  * Insq/Remq for the buffer hash lists.
  180.  */
  181. #define    bremhash(bp) { \
  182.     (bp)->b_back->b_forw = (bp)->b_forw; \
  183.     (bp)->b_forw->b_back = (bp)->b_back; \
  184. }
  185. #define    binshash(bp, dp) { \
  186.     (bp)->b_forw = (dp)->b_forw; \
  187.     (bp)->b_back = (dp); \
  188.     (dp)->b_forw->b_back = (bp); \
  189.     (dp)->b_forw = (bp); \
  190. }
  191.  
  192. /*
  193.  * Insq/Remq for the buffer free lists.
  194.  */
  195. #define    bremfree(bp) { \
  196.     (bp)->av_back->av_forw = (bp)->av_forw; \
  197.     (bp)->av_forw->av_back = (bp)->av_back; \
  198. }
  199. #define    binsheadfree(bp, dp) { \
  200.     (dp)->av_forw->av_back = (bp); \
  201.     (bp)->av_forw = (dp)->av_forw; \
  202.     (dp)->av_forw = (bp); \
  203.     (bp)->av_back = (dp); \
  204. }
  205. #define    binstailfree(bp, dp) { \
  206.     (dp)->av_back->av_forw = (bp); \
  207.     (bp)->av_back = (dp)->av_back; \
  208.     (dp)->av_back = (bp); \
  209.     (bp)->av_forw = (dp); \
  210. }
  211.  
  212. /*
  213.  * Take a buffer off the free list it's on and
  214.  * mark it as being use (B_BUSY) by a device.
  215.  */
  216. #define    notavail(bp) { \
  217.     int x = splbio(); \
  218.     bremfree(bp); \
  219.     (bp)->b_flags |= B_BUSY; \
  220.     (void) splx(x); \
  221. }
  222.  
  223. #define    iodone    biodone
  224. #define    iowait    biowait
  225.  
  226. /*
  227.  * Zero out a buffer's data portion.
  228.  */
  229. #define    clrbuf(bp) { \
  230.     blkclr((bp)->b_un.b_addr, (unsigned)(bp)->b_bcount); \
  231.     (bp)->b_resid = 0; \
  232. }
  233.  
  234. #endif    _SYS_BUF_
  235.